package com.bank;

/**
 * Created by Administrator on 2017/4/13.
 */

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;

import com.bank.GOME_M27A.M27CCBbank;
import com.bank.lenovoz5.Z5CCBbank;
import com.entity.User;
import com.utils.ChatClient;
import com.utils.CodeUtils;
import com.utils.Constants;
import com.utils.FileHelper;
import com.utils.ImageView;
import com.utils.LogToFile;
import com.utils.PinYinUtil;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import static android.os.SystemClock.sleep;
import static com.utils.ChatClient.CCBMethodName;
import static com.utils.ChatClient.CODE_S;
import static com.utils.ChatClient.CODE_TIMER;
import static com.utils.ChatClient.C_updateBalance_W;
import static com.utils.ChatClient.ConfirmOrder;
import static com.utils.ChatClient.PAUSE;
import static com.utils.ChatClient.RUNING;
import static com.utils.ChatClient.S_paused_C;
import static com.utils.ChatClient.addWorkTime;
import static com.utils.ChatClient.getmap;
import static com.utils.ChatClient.list;
import static com.utils.ChatClient.mapDelete;
import static com.utils.ChatClient.setDevicesLog;
import static com.utils.ChatClient.userInfo;
import static com.utils.Constants.isReport;
import static com.utils.Constants.notReport;
import static com.utils.Constants.orderBankName;

/**
 * 建设银行自动化脚本
 */
@RunWith(AndroidJUnit4.class)
public class CCBbank extends Bank {
    Context context = InstrumentationRegistry.getTargetContext();
    User user;
    private String type = "abc";
    private boolean isCode = false;//用来判断是否输入过图片附加码
    private int SMS_num = 0;
    private int[][] xy_num = new int[][]
            {{126, 935}, {365, 935}, {604, 935},
                    {126, 1040}, {365, 1040}, {604, 1040},
                    {126, 1147}, {365, 1147}, {604, 1147},
                    {126, 1245}, {365, 1245}};
    //验证码键盘，讯飞数字键盘，默认2016尺寸
    private int[][] xy_num_xunfei = new int[][]{{300, 1415}, {545, 1415}, {780, 1415},
            {300, 1575}, {545, 1575}, {780, 1575},
            {300, 1755}, {545, 1755}, {780, 1755},
            {545, 1925}};
    private int[][] xy_num_xunfei_1920 = new int[][]{{300, 1320}, {540, 1320}, {780, 1320},
            {300, 1500}, {540, 1500}, {780, 1500},
            {300, 1660}, {540, 1660}, {780, 1660}, {540, 1830}};
    private int[][] xy_num_xunfei_2102 = new int[][]{
            {300, 1500}, {540, 1500}, {780, 1500},
            {300, 1670}, {540, 1670}, {780, 1670},
            {300, 1840}, {540, 1840}, {780, 1840},
            {540, 2011}};
    //    private int[][] xy_abc = new int[][]{
    //            {46, 938}, {115, 938}, {185, 938}, {255, 938}, {330, 938}, {400, 938}, {467, 938}, {540, 938}, {610, 938}, {680, 938},
    //            {46, 1041}, {115, 1041}, {185, 1041}, {255, 1041}, {330, 1041}, {400, 1041}, {467, 1041}, {540, 1041}, {610, 1041},
    //            {680, 1041},
    //            {115, 1139}, {185, 1139}, {255, 1139}, {330, 1139}, {400, 1139}, {467, 1139}, {540, 1139}, {610, 1139}, {680, 1139},
    //            {148, 1242}, {220, 1242}, {290, 1242}, {362, 1242}, {437, 1242}, {507, 1242}, {579, 1242}};
    private int[][] xy_abc = new int[][]{
            {65, 1380}, {175, 1380}, {275, 1380}, {380, 1380}, {490, 1380}, {600, 1380}, {705, 1380}, {810, 1380}, {915, 1380}, {1020, 1380},
            {65, 1530}, {175, 1530}, {275, 1530}, {380, 1530}, {490, 1530}, {600, 1530}, {705, 1530}, {810, 1530}, {915, 1530}, {1020, 1530},
            {175, 1685}, {275, 1685}, {380, 1685}, {490, 1685}, {600, 1685}, {705, 1685}, {810, 1685}, {915, 1685}, {1020, 1685},
            {220, 1840}, {330, 1840}, {430, 1840}, {545, 1840}, {655, 1840}, {760, 1840}, {870, 1840}};

    {
        BANK_FLAG = "CCB";
        BANK_NAME = "中国建设银行";
        carrier = android.os.Build.MODEL;//机型
        smsCode = "95533";
        smsCode_86 = "+8695533";
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
        ratio = screenWidth / 720f;
        ratioH = screenHeight / 1920f;
    }

    @Test
    public void demo() throws UiObjectNotFoundException {
        //启动银行app
        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        LogToFile.init(InstrumentationRegistry.getTargetContext(), Constants.PROT);
        mDevice.pressHome();
        mDevice.pressHome();
        Constants.CODE = "";
        //启动银行app
        showMsg("进入建设银行");
        UiObject x = mDevice.findObject(new UiSelector().text("中国建设银行"));
        x.click();
        Constants.getsTheModelAndVersionNumberAndVersionName(context, BANK_NAME);
        keyPhone(screenHeight);
        //动态注册短信广播
        CodeUtils.initSMSReceiver(context);
        sleep(ChatClient.overtime_5);
        CloseNetwork();
        if (android.os.Build.MODEL.equals("Lenovo L78011")) {
            showMsg("联想Z5设备");
            new Z5CCBbank(this);
            return;
        } else if (android.os.Build.MODEL.contains("2017M27A")) {
            showMsg("国美M27设备");
            new M27CCBbank(this);
            return;
        }
        sleep(ChatClient.overtime_5);
        //检查usb连接状态
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "检测弹窗广告结束", notReport);
            if (isOutTime) {
                transfer();
                break;
            }
            if (Constants.STATE_USB) {
                UiObject updateDialog = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_close"));
                if (updateDialog.exists()) {
                    showMsg("======检测到更新弹窗，点击关闭按钮=====");
                    updateDialog.click();
                }
                sleep(ChatClient.overtime_1);
                UiObject tip = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tip_view_pager"));
                UiObject close = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close"));
                if (tip.exists()) {
                    showMsg("======检测到viewpager;点击关闭按钮=====");
                    close.click();
                } else if (close.exists()) {
                    showMsg("======检测到关闭按钮;点击关闭按钮=====");
                    close.click();
                }
            }
        }
    }

    //键盘适配
    public void keyPhone(int screenHeight) {
        showMsg("适配键盘坐标...");
        String h = String.valueOf(screenHeight);
        switch (h) {
            case "1920":
                xy_num_xunfei = xy_num_xunfei_1920;
                break;
            case "2102":
                xy_num_xunfei = xy_num_xunfei_2102;
                break;
            case "2016":
                break;
        }
    }

    @Override
    public void keyPhone(String device) {

    }


    //检索转账：进入转账
    public void transfer() throws UiObjectNotFoundException {
        //点击进入转账
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "点击转账结束...", notReport);
            if (isOutTime) {
                break;
            }
            UiObject allow = mDevice.findObject(new UiSelector().text("允许").resourceId("com.android.packageinstaller:id/permission_allow_button"));
            if (allow.exists()) {
                //进入转账
                showMsg("点击A-MOB正在尝试读取帐号信息对话框的允许");
                allow.click();
            }
            //首页转账ID
            UiObject transfer = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/main_home_smart_transfer"));
            if (transfer.exists()) {
                showMsg("点击转账1");
                transfer.click();
            }
            sleep(ChatClient.overtime_1);
        }
        //获取账号信息
        ChatClient.start();
        while (true) {
            if (userInfo.equals("")) {
                ChatClient.msg("<YZF>{'header':'" + ChatClient.M_GET_BANK_LOGIN_INFO_P + "'}</YZF>");
                sleep(ChatClient.overtime_5);
            } else {
                user = new User();
                String[] res = userInfo.split(" ");
                for (int i = 0; i < res.length; i++) {
                    switch (i) {
                        case 0:
                            user.setUserName(res[0]);
                            break;
                        case 1:
                            user.setPwd(res[1]);
                            break;
                        case 2:
                            user.setBankpwd(res[2]);
                            break;
                        case 3:
                            user.setUsbPayPwd(res[3]);
                            break;
                        case 4:
                            user.setUseType(res[4]);
                            break;
                        case 5:
                            user.setBankId(res[5]);
                            break;
                    }
                }
                break;
            }
        }
        Login();
    }

    //进入登录页面补充用户信息
    public void Login() {
        try {
            CCBMethodName = "Login";
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "《转账》查找超时...", isReport);
                if (isOutTime) {
                    return;
                }
                UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
                if (zhuanzhang.exists()) {
                    showMsg("点击转账");
                    zhuanzhang.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_5);
            //获取页面上登录节点
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "登录页面超时...", isReport);
                if (isOutTime) {
                    break;
                }
                Log.e("报错点", "报错点1 ");
                UiObject login = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_userInfo"));
                if (login.exists()) {
                    UiObject pwd = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_password"));
                    pwd.legacySetText("");
                    //截取键盘模拟用户输入登录密码
                    if (user.getPwd() != null) {
                        type = "abc";
                        setClick(user.getPwd());
                    }
                    Log.e("报错点", "报错点2");
                    sleep(ChatClient.overtime_2);
                    if (screenHeight != 2102) {
                        mDevice.click((int) (645 * ratio), (int) (830 * ratio));
                    } else {
                        mDevice.click((int) (645 * ratio), 1430);
                    }
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }
            while (true) {
                UiObject username = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_userInfo"));
                if (username.exists()) {
                    String name = username.getText();
                    if (!name.equals("身份信息获取中...")) {
                        if (name.equals("获取用户信息失败")) {
                            while (true) {
                                UiObject btn_getUserInfo = mDevice.findObject(new UiSelector().resourceId("com.chinamworld" +
                                        ".main:id/btn_getUserInfo"));
                                if (btn_getUserInfo.exists()) {
                                    btn_getUserInfo.click();
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    }
                }
                Log.e("报错点", "报错点3");
            }
            //登录
            UiObject lgbut = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            if (lgbut.exists())
                lgbut.click();
            setRemittance();
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 登录成功后进入转账
     *
     * @throws UiObjectNotFoundException
     */
    public void setRemittance() {
        try {
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "进入转账页面失败...", Constants.isReport);
                if (isOutTime) {
                    return;
                }
                UiObject remittance = CodeUtils.getUiObject_textOrId("转账", "com.chinamworld.main:id/ccb_title_text");
                UiObject close = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_red_packet_close"));
                if (remittance.exists()) {
                    CCBMethodName = "setTimerun";
                    //判断是否存在订单
                    ChatClient.loginS();
                    showMsg("=====上报登录成功========");
                    break;
                } else if (close.exists()) {
                    close.click();
                    sleep(ChatClient.overtime_1);
                    close();
                }
            }
            while (true) {
                sleep(ChatClient.overtime_3);
                RUNING = list.size() > 0;
                if (RUNING) {
                    orderBankName = Constants.getBank(list.get(0).getBankName(), "CCB");
                    if (ConfirmOrder) {
                        showMsg("====开始查账=====");
                        auditOrder();
                    } else {
                        showMsg("====开始转账=====");
                        remittanceLongin();
                    }
                } else {
                    if (PAUSE) {
                        setTimerun();
                    } else {
                        S_paused_C();
                        sleep(ChatClient.overtime_1);
                    }
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 关闭抢红包弹窗
     *
     * @throws UiObjectNotFoundException
     */
    public void close() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "主页按钮超时1...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject transfer = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/main_home_smart_transfer"));
            if (transfer.exists()) {
                showMsg("点击1");
                transfer.click();
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "主页按钮超时2...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
            if (zhuanzhang.exists()) {
                if (screenHeight != 1920) {
                    zhuanzhang.click();
                } else {
                    mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                }
                break;
            }
        }
    }

    /**
     * 转账汇款
     */
    public void remittanceLongin() {
        try {
            showMsg("=====进入转账========");
            SMS_num = 0;
            CCBMethodName = "remittanceLongin";
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "转账页超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject function = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
                UiObject username_ = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_cash_name"));
                if (function.exists()) {
                    if (screenHeight != 1920) {
                        function.click();
                    } else {
                        mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                        mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                    }
                    sleep(ChatClient.overtime_2);
                } else if (username_.exists()) {
                    sleep(ChatClient.overtime_1);
                    username_.setText(list.get(0).getUserName());
                    showMsg("=====输入收款人========");
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            while (true) {
                UiObject moeny = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_pay_info"));
                if (moeny.exists()) {
                    if (moeny.getText().indexOf("-") == -1) {
                        String[] res = moeny.getText().split("  ");
                        sumMoney = res[2];
                        sumMoney = sumMoney.replaceAll(",", "");
                        C_updateBalance_W(Double.parseDouble(sumMoney));
                        showMsg("===本地保存余额===");
                        String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                        FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                    }
                    break;
                }
            }
            showMsg("===获取金额====:");
            if (sumMoney.equals("")) {
                sumMoney = "-1";
            } else {
                showMsg("===本地保存余额====:");
                String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
            }
            //账户余额是否大于转账金额
            if (Double.parseDouble(sumMoney) < Double.parseDouble(list.get(0).getMoney())) {
                showMsg("===余额不足====");
                ChatClient.reportTransferOrder(BANK_NAME, "账户余额不足", sumMoney, 1);
                sleep(ChatClient.overtime_2);
                return;
            }
            sleep(ChatClient.overtime_1);
            while (true) {
                UiObject bankNo_ = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_collection_account"));
                UiObject bank = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_bank"));
                if (bankNo_.exists() && bank.exists()) {
                    bankNo_.click();
                    sleep(ChatClient.overtime_1);
                    showMsg("=====输入账卡号========");
                    bankNo_.setText(list.get(0).getBankNo());
                    sleep(ChatClient.overtime_1);
                    showMsg("=====选择银行点击========");
                    bank.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "自动识别成功...", Constants.notReport);
                if (outTime) {
                    break;
                }
                UiObject mTV_bank = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_bank"));
                if (mTV_bank.exists()) {
                    String bankName = mTV_bank.getText();
                    if (bankName.contains("请选择收款银行")) {
                        if (addBank()) {
                            break;
                        } else {
                            mDevice.pressBack();
                            return;
                        }
                    }
                }
            }
            showMsg("=====银行选择完毕========");
            sleep(ChatClient.overtime_2);
            //返回转账页面
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "金额控件超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject money = CodeUtils.getUiObject_textOrId("请输入转账金额", "com.chinamworld.main:id/et_tran_amount");
                if (money.exists()) {
                    sleep(500);
                    money.setText(list.get(0).getMoney());
                    showMsg("=====金额输入完毕========");
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "坐标点击下一步...", Constants.notReport);
                if (outTime) {
                    if (screenHeight != 2102) {
                        mDevice.click((int) (400 * ratio), (int) (1240 * ratio));
                    } else {
                        mDevice.click(540, 1950);
                    }
                    break;
                }
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                UiObject ok1 = CodeUtils.getUiObject_textOrClass("下一步", "android.widget.Button");
                showMsg("-----檢測下一步按鈕-----");
                if (ok.exists() || ok1.exists()) {
                    if (ok.exists()) {
                        ok.click();
                        showMsg("===点击下一步====ID点击1");
                        break;
                    }
                    if (ok1.exists()) {
                        ok1.click();
                        showMsg("===点击下一步====ID点击2");
                        break;
                    }
                    CCBMethodName = "Submit";//提交
                }
                sleep(ChatClient.overtime_1);
            }
            //处理 检测查询帐户开户机构失败超时弹窗
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "检测查询帐户开户机构失败超时...", Constants.notReport);
                if (outTime) {
                    break;
                }
                UiObject text = mDevice.findObject(new UiSelector().className("android.widget.TextView").resourceId("com.chinamworld" +
                        ".main:id/tv_dlg_content"));
                UiObject sure = mDevice.findObject(new UiSelector().className("android.widget.TextView").resourceId("com.chinamworld" +
                        ".main:id/dlg_right_tv"));
                if (text.exists() && sure.exists()) {
                    String s = text.getContentDescription();
                    String s1 = text.getText();
                    if (s.contains("查询帐户开户机构失败") || s1.contains("查询帐户开户机构失败")) {
                        showMsg("===检测到查询帐户开户机构失败===");
                        sure.click();
                        ChatClient.reportTransferOrder(BANK_NAME, "账户错误...", sumMoney, 1);
                        sleep(ChatClient.overtime_2);
                        return;
                    }
                }
            }
            showMsg("===检测是否点击了下一步按钮===");
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "再次检测下一步按钮超时...", Constants.notReport);
                if (outTime) {
                    break;
                }
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                UiObject ok1 = CodeUtils.getUiObject_textOrClass("下一步", "android.widget.Button");
                showMsg("===第二次檢測下一步按鈕===");
                if (ok.exists() || ok1.exists()) {
                    showMsg("===第二次检测到下一步按鈕===" + "点击坐标");
                    mDevice.click((screenWidth / 2), (int) (1240 * ratio));
                    break;
                }
                sleep(ChatClient.overtime_1);
            }

            if (isOverMax(list.get(0).getMoney())) {
                showMsg("----开户行信息---");
                String[] array = list.get(0).getBankAdr().split("-");
                List<String> bankInfo = new ArrayList<>();
                String s = "";
                for (int i = 0; i < array.length; i++) {
                    if (i < 2) {
                        bankInfo.add(array[i]);
                    } else {
                        if (array.length == 3) {
                            bankInfo.add(array[i]);
                        } else {
                            showMsg("----开户行截取超过3---");
                            if (i == 2) {
                                s += array[i];
                            } else {
                                s += "-" + array[i];
                            }
                            showMsg("----拼接开户行后面的字段---");
                            if (i == array.length - 1) {
                                showMsg("----拼接完成---");
                                bankInfo.add(s);
                            }
                        }
                    }
                }
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择省份====");
                chooseProvice(bankInfo.get(0));
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择城市====");
                addWorkTime(ChatClient.overtime_30);
                chooseCity(bankInfo.get(1));
                sleep(ChatClient.overtime_2);
                showMsg("===准备进入选择具体支行====");
                addWorkTime(ChatClient.overtime_10);
                chooseBank(bankInfo.get(2));
                sleep(ChatClient.overtime_8);
                showMsg("===准备进入测试返回====");
            } else {
                finishOrder();
            }
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 完成转账流程
     */
    private void finishOrder() throws UiObjectNotFoundException {
        CCBMethodName = "remittanceLongin";
        showMsg("====继续1====");
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "无法继续...", Constants.isReport);
            if (outTime) {
                if (screenHeight != 2102) {
                    mDevice.click((int) (540 * ratio), (int) (1240 * ratio));
                } else {
                    mDevice.click(540, 1950);
                }
                break;
            }
            UiObject jx0 = CodeUtils.getUiObject_textOrId("继续", "com.chinamworld.main:id/dlg_right_tv");
            UiObject qr = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm").text("确定"));//确认按钮
            UiObject code = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_title").text("请输入验证码"));
            UiObject btn_right1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1").text("下一步"));

            if (jx0.exists()) {
                if (screenHeight != 1920) {
                    jx0.click();
                } else {
                    mDevice.click((int) (520 * ratio), (int) (767 * ratio));
                }
                showMsg("===点击继续====");
                break;
            } else if (qr.exists()) {
                qr.click();
                showMsg("===确认===");
                break;
            } else if (code.exists()) {
                showMsg("===请输入验证码====");
                break;
            } else if (btn_right1.exists()) {
                btn_right1.click();
                showMsg("===下一步====");
            }
        }
        showMsg("=====TV_TIPS=====2");
        sleep(ChatClient.overtime_3);
        getCodeType();
        CCBMethodName = "Re_send";
        //判断是否获取到短信
        ChatClient.addWorkTime(ChatClient.overtime_60);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_180, "短信获取失败...", Constants.isReport);
            if (outTime) {
                break;
            }
            //转账结果页面
            UiObject result = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ccb_title_right_btn"));
            if (getState(Constants.SMSMESSAGE, Constants.TV_TIPS)) {
                showMsg("===短信验证码获取成功====");
                break;
            } else if (result.exists()) {
                showMsg("===免验证====");
                ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                getUserInfo(sumMoney);
                return;
            } else {
                //短信请求三次重启
                if (smsNumExceed()) {
                    return;
                }
                while (true) {
                    UiObject text_code = CodeUtils.getUiObject_textOrId("重新获取", "com.chinamworld.main:id/re_send");
                    if (text_code.exists()) {
                        showMsg("===重新获取验证码1====");
                        ChatClient.addWorkTime(ChatClient.overtime_60);
                        text_code.click();
                        sleep(ChatClient.overtime_10);
                        getCodeType();
                        break;
                    }
                }
            }
        }
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "验证码输入框超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject et_code = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
            if (et_code.exists()) {
                showMsg("===弹出验证码输入键盘=====");
                et_code.click();
                break;
            }
        }
        sleep(ChatClient.overtime_1);
        showMsg("===开始输入验证码====");
        if (user.getUseType().equals("1")) {
            setClickXunFeiN(Constants.CODE);
        } else {
            setClickXunFeiN(ChatClient.smsCode.getSmscode());
        }
        showMsg("===验证码输入完毕====");
        Constants.TV_TIPS = "";
        //完成
        sleep(ChatClient.overtime_2);
        if (screenHeight == 1920) {
            mDevice.click(980, 1160);
        } else if (screenHeight == 2016) {
            mDevice.click(990, 1250);
            mDevice.click(990, 1250);
        } else if (screenHeight == 2102) {
            mDevice.click(990, 1340);
            mDevice.click(990, 1340);
        } else {
            mDevice.click(765, 990);
        }
        showMsg("===收起验证码键盘=====");
        sleep(ChatClient.overtime_2);
        //判断金额是否超过30W
        UiObject checkbox = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/checkbox"));
        if (checkbox.exists()) {
            showMsg("===金额超过30W=====");
            checkbox.click();
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        sleep(ChatClient.overtime_1);

        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "验证码确定超时...", Constants.notReport);
            if (outTime) {
                if (screenHeight != 2102) {
                    mDevice.click((int) (360 * ratio), (int) (1050 * ratio));
                } else {
                    mDevice.click(540, 1680);
                }
                break;
            }
            sleep(ChatClient.overtime_2);
            UiObject sure = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                    ".main:id/btn_confirm"));
            showMsg("===检测验证码确定按钮=====");
            if (sure.exists()) {
                showMsg("===点击验证码确定=====");
                sure.click();
                break;
            }
        }
        sleep(ChatClient.overtime_2);
        showMsg("===确定点击完成=====");
        showMsg("===检测验证码是否正确=====");
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        showMsg("===检测验证码完成 没有错误弹窗=====");
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "验证码判定结束...", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject smsErrorUiObject = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
            if (smsErrorUiObject.exists()) {
                if (errorCodeRecord(smsErrorUiObject)) {
                    showMsg("===检测验证码错误=====");
                } else {
                    showMsg("===检测验证码正确=====");
                }
            }
        }
        Constants.CODE = "";
        Constants.SMSMESSAGE = "";
        Constants.TV_TIPS = "";
        CODE_TIMER = 0;
        //附加图形验证码
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "附加码超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            sleep(ChatClient.overtime_1);
            UiObject fpwd1 = mDevice.findObject(new UiSelector().text("请输入附加码").resourceId("com.chinamworld.main:id/tv_title"));
            if (fpwd1.exists()) {
                sleep(ChatClient.overtime_2);
                isCode = true;
                showMsg("===请输入附加码=====");
                imageCode_f();
                break;
            }
        }
        showMsg("===附加码输入完毕=====");
        //取款密码
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "获取图片验证码超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject fpwd0 = mDevice.findObject(new UiSelector().text("重新输入").className("android.widget.TextView"));
            UiObject fpwd1 = mDevice.findObject(new UiSelector().text("重新输入").className("android.widget.Button"));
            //图形验证码
            UiObject bpwd = CodeUtils.getUiObject_textOrId("请输入账户取款密码", "com.chinamworld.main:id/tv_title");
            //转账结果页面
            UiObject result = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ccb_title_right_btn"));
            if (fpwd0.exists()) {
                fpwd0.click();
                showMsg("===重新获取附加码验证=====");
                sleep(ChatClient.overtime_1);
                isCode = true;
                imageCode_f();
                sleep(ChatClient.overtime_2);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
            } else if (fpwd1.exists()) {
                fpwd1.click();
                showMsg("===重新获取附加码验证1=====");
                sleep(ChatClient.overtime_1);
                isCode = true;
                imageCode_f();
                sleep(ChatClient.overtime_2);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
            } else if (bpwd.exists()) {
                showMsg("===输入取款密码====1=");
                sleep(ChatClient.overtime_1);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                BankPwd();
                break;
            } else if (result.exists()) {
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        showMsg("===准备检测是否附加码输入错误=====");
        if (isCode) {
            showMsg("===附加码错误弹框出现=====");
            checkNumberDialog();
        } else {
            showMsg("===没有出现附加码错误弹框=====");
        }

        showMsg("===数组长度1====" + list.size());
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        addWorkTime(ChatClient.overtime_20);
        showMsg("===检测是否有限额弹框====");
        //检测是否有限额提醒
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 3 * 1000) {
                showMsg("==========检测是否有限额弹框超时==========");
                break;
            }
            sleep(ChatClient.overtime_1);
            UiObject text = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
            UiObject sure = CodeUtils.getUiObject_textOrId("确定", "com.chinamworld.main:id/dlg_right_tv");
            showMsg("===检测限额弹框=====");
            if (sure.exists()) {
                String info = text.getText();
                sure.click();
                sleep(2000);
                showMsg("===向电脑端发送待处理信息=====" + info);
                sendRePropcessInfo(info);
                return;
            }
        }
        showMsg("===检测限额完成====");
        showMsg("===数组长度====" + list.size());
        CODE_TIMER = 0;
        ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
        getUserInfo(sumMoney);
    }

    private boolean errorCodeRecord(UiObject ui) throws UiObjectNotFoundException {
        String errorTag = "验证码有误";
        if (!TextUtils.isEmpty(ui.getText()) && ui.getText().contains(errorTag)) {
            if (smsNumExceed()) {
                return true;
            }
            UiObject closeUi = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/dlg_right_tv"));
            if (closeUi.exists()) {
                closeUi.click();
                sleep(ChatClient.overtime_1);
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                UiObject ok1 = CodeUtils.getUiObject_containTextOrClass("下一步", "android.widget.Button");

                showMsg("===errorCodeRecord檢測下一步按鈕===");
                if (ok.exists() || ok1.exists()) {
                    showMsg("===errorCodeRecord检测到下一步按鈕===" + "点击坐标");
                    if (screenHeight != 2102) {
                        mDevice.click((screenWidth / 2), (int) (1240 * ratio));
                        mDevice.click((screenWidth / 2), (int) (1240 * ratio));
                    } else {
                        mDevice.click((screenWidth / 2), 1960);
                        mDevice.click((screenWidth / 2), 1960);
                    }
                }
                sleep(ChatClient.overtime_1);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean ouitTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_180, "短信错误...", Constants.isReport);
                    if (ouitTime) {
                        break;
                    }
                    //短信请求三次重启
                    if (getState(Constants.SMSMESSAGE, Constants.TV_TIPS)) {
                        showMsg("===短信验证码获取成功====");
                        break;
                    }
                    if (smsNumExceed()) {
                        return true;
                    }
                    while (true) {
                        UiObject text_code = CodeUtils.getUiObject_textOrId("重新获取", "com.chinamworld.main:id/re_send");
                        if (text_code.exists()) {
                            showMsg("===重新获取验证码2====");
                            ChatClient.addWorkTime(ChatClient.overtime_60);
                            text_code.click();
                            sleep(ChatClient.overtime_10);
                            getCodeType();
                            break;
                        }
                    }
                }

                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean ouitTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "errorCodeRecord2", Constants.isReport);
                    if (ouitTime) {
                        break;
                    }
                    UiObject et_code = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
                    if (et_code.exists()) {
                        et_code.click();
                        showMsg("===弹出验证码输入键盘=====");
                        break;
                    }
                }
                sleep(ChatClient.overtime_1);
                showMsg("===开始输入验证码====");
                if (user.getUseType().equals("1")) {
                    setClickXunFeiN(Constants.CODE);
                } else {
                    setClickXunFeiN(ChatClient.smsCode.getSmscode());
                }
                showMsg("===验证码输入完毕====");
                Constants.TV_TIPS = "";
                //完成
                sleep(ChatClient.overtime_2);
                if (screenHeight == 1920) {
                    mDevice.click(980, 1160);
                } else if (screenHeight == 2016) {
                    mDevice.click(980, 1250);
                } else if (screenHeight == 2102) {
                    mDevice.click(980, 1340);
                    mDevice.click(980, 1340);
                } else {
                    mDevice.click(765, 990);
                }
                showMsg("===收起验证码键盘=====");
                sleep(ChatClient.overtime_2);
                //判断金额是否超过30W
                UiObject checkbox = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/checkbox"));
                if (checkbox.exists()) {
                    showMsg("===金额超过30W=====");
                    checkbox.click();
                }
                sleep(ChatClient.overtime_1);
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "验证码确定超时", Constants.notReport);
                    if (outTime) {
                        if (screenHeight != 2102) {
                            mDevice.click((int) (360 * ratio), (int) (1050 * ratio));
                        } else {
                            mDevice.click((int) (360 * ratio), 1690);
                        }
                        break;
                    }
                    sleep(ChatClient.overtime_2);
                    UiObject sure = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com" +
                            ".chinamworld.main:id/btn_confirm"));
                    showMsg("===检测验证码确定按钮=====");
                    if (sure.exists()) {
                        showMsg("===点击验证码确定=====");
                        sure.click();
                        break;
                    }
                }
                sleep(ChatClient.overtime_2);
                showMsg("===确定点击完成=====");
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "弹窗超时...", Constants.notReport);
                    if (outTime) {
                        break;
                    }
                    UiObject smsErrorUiObject = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
                    if (smsErrorUiObject.exists()) {
                        if (errorCodeRecord(smsErrorUiObject)) {
                        }
                    }
                }
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    /**
     * 检测三次附加码
     */
    private void checkNumberDialog() throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_1);
        //附加码错误
        showMsg("=====检测附加码错误提示====第一次检测附加码错误提示");
        checkErrorDialog(1);
        sleep(ChatClient.overtime_1);
        showMsg("=====检测附加码错误提示====第二次检测附加码错误提示");
        checkErrorDialog(2);
        showMsg("=====附加码输入完毕=====附加码输入完毕=====");
    }

    /**
     * 判断短信发送次数是否超时
     */
    private boolean smsNumExceed() {
        //短信请求三次重启
        if (SMS_num < 2) {
            SMS_num += 1;
            return false;
        } else {
            ChatClient.timer(LogToFile.getMethodName(), "短信请求超次重启3...");
            return true;
        }
    }

    /**
     * 请求短信
     *
     * @param args1
     * @param args2
     * @return
     */
    public boolean getState(String args1, String args2) {
        showMsg("=====短信内容====" + args1 + "====" + args2 + "====" + user.getUseType());
        if (!user.getUseType().equals("1")) {
            sleep(ChatClient.overtime_8);
            if (SMS_num > 0) {
                sleep(ChatClient.overtime_20);
                showMsg("在次获取");
            }
            showMsg("第" + SMS_num + "次获取短信");
            ChatClient.requestSMSCode(user.getUserName(), user.getBankId());
            if (TextUtils.isEmpty(ChatClient.smsCode.getSmscode())) {
                return false;
            } else {
                if (ChatClient.smsCode.getTelephone().equals(user.getUserName())) {
                    showMsg("收到短信验证码：" + ChatClient.smsCode.getSmscode());
                    return true;
                } else {
                    String str = "收到短信验证码手机号不匹配";
                    showMsg(str + ChatClient.smsCode.getTelephone());
                    return false;
                }
            }
        } else {
            if (!args1.equals("") && !args2.equals("")) {
                String[] res = args2.split("发送");
                String sumMoney = res[1];
                sumMoney = sumMoney.replaceAll("为", "");
                showMsg("sumMoney = " + sumMoney);
                if (args1.contains(sumMoney)) {
                    System.out.println("包含");
                    return true;
                } else {
                    System.out.println("不包含");
                    return false;
                }
            } else {
                return false;
            }
        }
    }

    /**
     * 检测附加码错误提示 弹框
     *
     * @param i
     **/
    private void checkErrorDialog(int i) throws UiObjectNotFoundException {
        addWorkTime(ChatClient.overtime_10);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "第" + i + "次检测附加码错误提示超时", Constants.notReport);
            if (outTime) {
                return;
            }
            sleep(ChatClient.overtime_1);
            UiObject notice = CodeUtils.getUiObject_textOrId("图形验证码不正确，请重新输入！", "com.chinamworld.main:id/tv_dlg_content");
            showMsg("===检测是否有附加码错误提示=====");
            if (notice.exists()) {
                clickReBtn();
                break;
            }
        }
        showMsg("===再次获取附加码=====");
        sleep(ChatClient.overtime_1);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "第" + i + "checkErrorDialog超时", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject fpwd1 = mDevice.findObject(new UiSelector().text("请输入附加码").resourceId("com.chinamworld.main:id/tv_title"));
            if (fpwd1.exists()) {
                sleep(ChatClient.overtime_1);
                showMsg("====请输入附加码=====");
                imageCode_f();
                break;
            }
        }
    }

    /**
     * 点击图形验证码重新输入
     */
    private void clickReBtn() throws UiObjectNotFoundException {
        showMsg("===准备点击附加码重新输入=====");
        while (true) {
            UiObject ok = CodeUtils.getUiObject_textOrId("重新输入", "com.chinamworld.main:id/dlg_right_tv");
            if (ok.exists()) {
                showMsg("===点击附加码重新输入=====");
                ok.click();
                sleep(ChatClient.overtime_1);
                imageCode_f();
                sleep(ChatClient.overtime_2);
                break;
            }
        }
    }

    /**
     * 判断是否达到选择开户行的临界值
     *
     * @path sumMoney
     */
    private boolean isOverMax(String s) {
        boolean b = false;
        double c = 50000.00;//临界值为50000.00
        showMsg("===判断金额是否超过填写开户行的临界值====");
        double money = Double.parseDouble(s);
        if (money > c) {
            b = true;
        }
        showMsg("===判断金额是否超过填写开户行的临界值====" + b);
        return b;
    }

    /**
     * 选择具体网点
     */
    private void chooseBank(String s) throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_2);
        showMsg("===支行信息====" + s);
        while (true) {
            UiObject etSearch = mDevice.findObject(new UiSelector().className("android.widget.EditText").resourceId("com.chinamworld" +
                    ".main:id/search_et"));
            showMsg("===查找搜索控件====");
            if (etSearch.exists()) {
                showMsg("===找到搜索控件====");
                etSearch.setText(s);
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                /**
                 * 适配金立
                 */
                UiObject view = null;
                if (screenHeight == 1280) {
                    view = list.getChild(new UiSelector().className("android.view.View").index(0));
                } else {
                    view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
                }
                showMsg("===搜索银行====");
                if (view.exists()) {
                    showMsg("===点击银行支行====");
                    view.click();
                    break;
                } else {
                    showMsg("===未搜索到银行====");
                    UiObject layout = mDevice.findObject(new UiSelector().className("android.widget.LinearLayout").resourceId("com" +
                            ".chinamworld.main:id/ll_no_result"));
                    UiObject img = layout.getChild(new UiSelector().className("android.widget.ImageView").index(0));
                    showMsg("===检测未搜索到银行====");
                    if (img.exists()) {
                        UiObject close = mDevice.findObject(new UiSelector().className("android.widget.ImageButton").resourceId("com" +
                                ".chinamworld.main:id/cib_close"));
                        showMsg("===检测支行的关闭键====");
                        if (close.exists()) {
                            close.click();
                            returnBack("未找到该银行的开户行信息");
                            return;
                        }
                    }
                }
            }
        }
        finishOrder();
    }

    /**
     * 未搜索到网点返回
     */
    private void returnBack(String s) throws UiObjectNotFoundException {
        CCBMethodName = "remittanceLongin";
        sendUnBankInfo(s);
        showMsg("===上报未搜索到开户网点====");
        sleep(ChatClient.overtime_2);
        while (true) {
            UiObject tv = mDevice.findObject(new UiSelector().text("收款网点").className("android.widget.TextView").resourceId("com" +
                    ".chinamworld.main:id/ctv_title"));
            showMsg("===准备检测城市的关闭键====");
            if (tv.exists()) {
                UiObject close = mDevice.findObject(new UiSelector().className("android.widget.ImageButton").resourceId("com" +
                        ".chinamworld.main:id/cib_close"));
                if (close.exists()) {
                    showMsg("===点击城市的关闭键====");
                    close.click();
                    break;
                }
            }
        }
        sleep(2000);
        while (true) {
            UiObject tv = mDevice.findObject(new UiSelector().text("收款网点").className("android.widget.TextView").resourceId("com" +
                    ".chinamworld.main:id/ctv_title"));
            showMsg("===准备检测省份的关闭键====");
            if (tv.exists()) {
                UiObject close = mDevice.findObject(new UiSelector().className("android.widget.ImageButton").resourceId("com" +
                        ".chinamworld.main:id/cib_close"));
                if (close.exists()) {
                    showMsg("===点击省份的关闭键====");
                    close.click();
                    break;
                }
            }
        }
        sleep(2000);
        while (true) {
            UiObject tv = mDevice.findObject(new UiSelector().text("转账").className("android.widget.TextView").resourceId("com" +
                    ".chinamworld.main:id/ccb_title_text"));
            showMsg("===准备检测转账的关闭键====");
            if (tv.exists()) {
                UiObject back = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                        ".main:id/ccb_title_left_btn"));
                if (back.exists()) {
                    showMsg("===点击转账的关闭键====");
                    back.click();
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_8);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "预约转账超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("预约转账", "com.chinamworld.main:id/tv_function");
            if (zhuanzhang.exists()) {
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                showMsg("===转账完成进入转账页面=====");
                break;
            }
        }
    }

    /**
     * 选择城市
     */
    private void chooseCity(String city) {
        try {
            int textPosition = 0;
            showMsg("===准备选择市====");
            while (true) {
                sleep(ChatClient.overtime_2);
                showMsg("---城市----");
                String s1 = PinYinUtil.getPinYinFirstHeadChar(city);
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                UiObject view = null;
                if (screenHeight == 1280) {//适配金立
                    view = list.getChild(new UiSelector().className("android.view.View").index(textPosition));
                } else {
                    view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(textPosition));
                }
                showMsg("===查找控件，位置为====" + textPosition);
                if (list.exists()) {
                    if (view.exists()) {
                        UiObject text = view.getChild(new UiSelector().className("android.widget.TextView").index(0));
                        if (text.exists()) {
                            String s2 = text.getText();
                            showMsg("====准备选择市,找到标签====" + s2);
                            if (s1.equals(s2)) {
                                clickCity(view, city);
                                break;
                            } else {
                                if (s2.contains("银行")) {
                                    showMsg("===进入到选择支行界面，跳出循环====");
                                    break;
                                } else {
                                    addWorkTime(ChatClient.overtime_10);
                                    showMsg("===未找到标签====" + s1 + "与" + s2 + "不匹配");
                                    textPosition++;
                                }
                            }
                        } else {
                            showMsg("===未找到标签控件====");
                            //textPosition = 1;
                            textPosition++;
                        }
                    } else {
                        showMsg("===未找到标签====" + screenHeight + "当前位置为:" + textPosition);
                        if (textPosition == 0) {//判断是否为0位置防止不停的的滑动
                            textPosition = 1;
                        } else {
                            showMsg("===未找到标签，向上滑动====");
                            if (screenHeight == 1280) {//适配金立
                                mDevice.drag(200, 600, 540, 330, 30);//这里坐标不用转换
                            } else {
                                mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                            }
                            addWorkTime(ChatClient.overtime_10);
                            showMsg("====准备选择市==滑动====");
                            sleep(ChatClient.overtime_2);
                            textPosition = 0;
                        }
                    }
                }
            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 找到对应的城市点击
     *
     * @param view
     * @param s
     */
    private void clickCity(UiObject view, String s) throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_2);
        int position = 0;
        int times = 0;
        while (true) {
            sleep(ChatClient.overtime_2);
            UiObject layout = view.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
            if (layout.exists()) {
                UiObject text = layout.getChild(new UiSelector().className("android.widget.TextView").index(position));
                if (text.exists()) {
                    showMsg("===找到控件====");
                    String city = text.getText();
                    showMsg("===找到控件====" + city);
                    if (city.contains(s)) {
                        text.click();
                        showMsg("===点击城市====");
                        times = 0;
                        break;
                    } else {
                        showMsg("===城市不匹配====" + position);
                        showMsg("===滑动====");
                        position += 2;
                    }
                } else {
                    showMsg("位置" + position + "未找到控件");
                    times++;
                    if (times > 3) {
                        times = 0;
                        showMsg("===未找到控件，向上滑动====");
                        if (screenHeight == 1280) {//适配金立
                            mDevice.drag(200, 600, 540, 330, 30);//这里坐标不用转换
                        } else {
                            mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                        }
                        getCity(s, position);
                        break;
                    }
                }
            } else {
                showMsg("===找不到控件====" + position);
                times++;
                if (times > 3) {
                    times = 0;
                    showMsg("===未找到标签，向上滑动====");
                    if (screenHeight == 1280) {//适配金立
                        mDevice.drag(200, 600, 540, 330, 30);//这里坐标不用转换
                    } else {
                        mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                    }
                    getCity(s, position);
                    break;
                }
            }
        }
    }

    /**
     * 继续查找城市,判断是否存在标签
     */
    private void getCity(String s, int position) throws UiObjectNotFoundException {
        sleep(2000);
        String s1 = PinYinUtil.getPinYinFirstHeadChar(s);
        showMsg("准备比对标签:" + s1);
        int times = 0;
        while (true) {
            UiObject tab = mDevice.findObject(new UiSelector().descriptionContains(s1).className("android.widget.TextView"));
            UiObject tab1 = mDevice.findObject(new UiSelector().text(s1).className("android.widget.TextView"));
            if (tab.exists()) {
                showMsg("字母标签存在，查找城市1");
                getTabToCity(s);
                break;
            } else if (tab1.exists()) {
                showMsg("字母标签存在，查找城市2");
                getTabToCity(s);
                break;
            } else {
                times++;
                if (times > 3) {
                    times = 0;
                    showMsg("字母标签不存在，查找城市3");
                    getNoTabToCity(s, position);
                    break;
                }
            }
        }
    }

    /**
     * 标签不存在  继续查找城市
     */
    private void getNoTabToCity(String s, int position) throws UiObjectNotFoundException {
        int times = 0;
        while (true) {
            UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                    ".main:id/cslhl_content"));
            UiObject view = null;
            if (screenHeight == 1280) {//适配金立
                view = list.getChild(new UiSelector().className("android.view.View").index(0));
            } else {
                view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(0));
            }
            UiObject layout = view.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
            UiObject text = layout.getChild(new UiSelector().className("android.widget.TextView").index(position));
            showMsg("===没有字母标签，查找具体的城市====");
            if (text.exists()) {
                String s1 = text.getText();
                showMsg("===没有字母标签，找到的城市====" + s1);
                if (s1.contains(s)) {
                    showMsg("===没有字母标签，找到的城市====" + s1 + "与所要查找的" + s + "一致");
                    text.click();
                    break;
                } else {
                    showMsg("===城市不匹配====");
                    position += 2;
                }
            } else {
                times++;
                if (times > 3) {
                    times = 0;
                    if (screenHeight == 1280) {//适配金立
                        mDevice.drag(200, 600, 540, 330, 30);//这里坐标不用转换
                    } else {
                        mDevice.drag(200, 700, 540, 0, 30);//这里坐标不用转换
                    }
                    showMsg("------滑动----");
                    position += 2;
                }
            }
        }
    }

    /**
     * 标签存在  继续查找城市
     */
    private void getTabToCity(String s) {
        chooseCity(s);
    }

    /**
     * 选择省份
     *
     * @param s
     */
    private void chooseProvice(String s) {
        try {
            showMsg("---省份----" + s);
            s = s.replace("省", "");
            showMsg("---将传过来的省去掉----");
            while (true) {
                sleep(ChatClient.overtime_2);
                String s1 = PinYinUtil.getPinYinFirstHeadChar(s);
                showMsg("===获取首字母====");
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                UiObject normal = list.getChild(new UiSelector().text("常用").className("android.widget.TextView"));
                showMsg("===常用匹配====");
                if (normal.exists()) {
                    UiObject layout = list.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
                    UiObject text = layout.getChild(new UiSelector().className("android.widget.TextView").index(0));
                    showMsg("===通过常用匹配====");
                    if (text.exists()) {
                        String s2 = text.getText();
                        if (s.equals(s2)) {
                            text.click();
                            showMsg("===通过常用匹配到城市====" + s2);
                        } else {
                            showMsg("===未通过常用匹配到城市====" + s1);
                            check(s1, s);
                        }
                        break;
                    }
                }
            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过首字母查找省
     */
    private void check(String s1, String province) throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_2);
        showMsg("===首字母查找====");
        int provincePosition = 0;//省的位置
        if (screenHeight == 1280) {
            //适配金立
            switch (s1) {
                case "A":
                    mDevice.click(673, 455);
                    break;
                case "B":
                    mDevice.click(673, 490);
                    break;
                case "C":
                    mDevice.click(673, 530);
                    break;
                case "F":
                    mDevice.click(673, 565);
                    break;
                case "G":
                    mDevice.click(673, 605);
                    break;
                case "H":
                    mDevice.click(673, 645);
                    break;
                case "J":
                    mDevice.click(673, 690);
                    break;
                case "L":
                    mDevice.click(673, 725);
                    break;
                case "N":
                    mDevice.click(673, 763);
                    break;
                case "Q":
                    mDevice.click(673, 802);
                    break;
                case "S":
                    mDevice.click(673, 842);
                    break;
                case "T":
                    provincePosition = 1;
                    mDevice.click(673, 880);
                    break;
                case "X":
                    provincePosition = 1;
                    mDevice.click(673, 919);
                    break;
                case "Y":
                    provincePosition = 1;
                    mDevice.click(673, 959);
                    break;
                case "Z":
                    provincePosition = 1;
                    mDevice.click(673, 997);
                    break;
            }
        } else {
            switch (s1) {
                case "A":
                    mDevice.click(1010, 700);
                    break;
                case "B":
                    mDevice.click(1010, 760);
                    break;
                case "C":
                    mDevice.click(1010, 820);
                    break;
                case "F":
                    mDevice.click(1010, 870);
                    break;
                case "G":
                    mDevice.click(1010, 920);
                    break;
                case "H":
                    mDevice.click(1010, 960);
                    break;
                case "J":
                    mDevice.click(1010, 1020);
                    break;
                case "L":
                    mDevice.click(1010, 1070);
                    break;
                case "N":
                    mDevice.click(1010, 1120);
                    break;
                case "Q":
                    mDevice.click(1010, 1170);
                    break;
                case "S":
                    mDevice.click(1010, 1230);
                    break;
                case "T":
                    provincePosition = 1;
                    mDevice.click(1010, 1270);
                    break;
                case "X":
                    provincePosition = 1;
                    mDevice.click(1010, 1320);
                    break;
                case "Y":
                    provincePosition = 1;
                    mDevice.click(1010, 1370);
                    break;
                case "Z":
                    provincePosition = 1;
                    mDevice.click(1010, 1450);
                    break;
            }
        }
        sleep(3000);
        while (true) {
            UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                    ".main:id/cslhl_content"));
            /**
             * 适配金立
             */
            UiObject view = null;
            if (screenHeight == 1280) {
                view = list.getChild(new UiSelector().className("android.view.View").index(provincePosition));
            } else {
                view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(provincePosition));
            }
            UiObject text = view.getChild(new UiSelector().className("android.widget.TextView").index(0));
            showMsg("===准备检测控件是否存在====" + provincePosition);
            if (text.exists()) {
                String s = text.getText();
                showMsg("===匹配字母====" + s);
                if (s.equals(s1)) {
                    showMsg("===首字母匹配到====" + s);
                    getProvince(province, provincePosition);
                    break;
                } else {
                    showMsg("===首字母未匹配到====" + s1);
                    provincePosition++;
                }
            }
        }
    }

    /**
     * 在某一字母下查找
     */
    private void getProvince(String province, int provincePosition) {
        try {
            int position = 0;
            sleep(ChatClient.overtime_2);
            showMsg("===准备具体查找====" + province);
            while (true) {
                UiObject list = mDevice.findObject(new UiSelector().className("android.widget.ListView").resourceId("com.chinamworld" +
                        ".main:id/cslhl_content"));
                /**
                 * 适配金立
                 */
                UiObject view = null;
                if (screenHeight == 1280) {
                    view = list.getChild(new UiSelector().className("android.view.View").index(provincePosition));
                } else {
                    view = list.getChild(new UiSelector().className("android.view.ViewGroup").index(provincePosition));
                }

                UiObject linearLayout = view.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
                UiObject text = linearLayout.getChild(new UiSelector().className("android.widget.TextView").index(position));
                showMsg("===遍历子选项====" + position);
                if (text.exists()) {
                    showMsg("===listview====");
                    Log.d("====准备具体查找====", "===listview====");
                    String s = text.getText();
                    showMsg("===通过该内容进行匹配====" + s);
                    if (province.contains(s)) {
                        showMsg("===内容匹配====" + s);
                        text.click();
                        break;
                    } else {
                        showMsg("===内容不匹配====" + s);
                        position += 2;//每次递增2 是因为有分割线
                    }
                }
            }

        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void BankPwd() throws UiObjectNotFoundException {
        UiObject et_code1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
        et_code1.click();
        sleep(ChatClient.overtime_1);
        showMsg("输入取款密码");
        setClickN(user.getBankpwd());
        Constants.TV_TIPS = "";
        sleep(ChatClient.overtime_1);
        if (screenHeight != 2102) {
            mDevice.click((int) (663 * ratio), (int) (816 * ratio));
        } else {
            mDevice.click((int) (663 * ratio), 1420);
        }
        sleep(ChatClient.overtime_1);
        imageCode();
    }

    /**
     * 图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void imageCode() throws UiObjectNotFoundException {
        long startTime = System.currentTimeMillis();
        while (true) {
            sleep(ChatClient.overtime_1);
            boolean outTime = CodeUtils.outTime(startTime, ChatClient.overtime_30, "imageCode超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            try {
                showMsg("===imageCode====:");
                CODE_S = "";
                String code = ImageView.getImage("com.chinamworld.main:id/native_graph_iv", "中国建设银行");
                if (!code.equals("###")) {
                    UiObject et_code2 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/native_graph_et"));
                    et_code2.setText(code);
                    sleep(1500);
                    showMsg("===code====:" + code);
                }
            } catch (Exception e) {
                setDevicesLog(e.toString());
                e.printStackTrace();
            } finally {
                ChatClient.vrifyCodeText = "";
            }
            sleep(ChatClient.overtime_1);
            //确定
            UiObject ok1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            //如果确定按钮可用，点击，不可用重新填写验证码
            if (ok1.isEnabled()) {
                ok1.click();
                showMsg("----点击确定1---");
                break;
            } else {
                showMsg("----确认按钮不可用，重新请求验证码1---");
                UiObject image = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/native_graph_iv"));
                image.click();
                sleep(ChatClient.overtime_4);
            }
        }
    }

    /**
     * 附加图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void imageCode_f() throws UiObjectNotFoundException {
        long startTime = System.currentTimeMillis();
        while (true) {
            boolean outTime = CodeUtils.outTime(startTime, ChatClient.overtime_30, "imageCode_f 超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            try {
                CODE_S = "";
                CODE_TIMER++;
                showMsg("===第" + CODE_TIMER + "次重新获取附加码验证=====");
                addWorkTime(ChatClient.overtime_10);
                String code = ImageView.getImage("com.chinamworld.main:id/iv_addition_code", "中国建设银行");
                if (!code.equals("###")) {
                    UiObject et_code2 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_code"));
                    showMsg("----获取图片附加码信息---" + code);
                    et_code2.legacySetText("");
                    sleep(ChatClient.overtime_1);
                    et_code2.setText(code);
                    sleep(ChatClient.overtime_1);
                    if (screenHeight == 2102) {
                        mDevice.click((int) (663 * ratio), 1420);
                    } else if (screenHeight == 2016) {
                        mDevice.click((int) (663 * ratio), 1320);
                    } else if (screenHeight == 1920) {
                        mDevice.click((int) (663 * ratio), 1235);
                    } else {
                        mDevice.click((int) (663 * ratio), (int) (880 * ratio));
                    }
                    showMsg("---点击确定---" + code);
                    sleep(ChatClient.overtime_1);
                    showMsg("===code====:" + code);
                }
            } catch (UiObjectNotFoundException e) {
                showMsg("未找到控件异常:" + e.toString());
            } catch (Exception e) {
                setDevicesLog(e.toString());
                e.printStackTrace();
            } finally {
                ChatClient.vrifyCodeText = "";
            }
            sleep(ChatClient.overtime_1);
            //确定
            UiObject ok1 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            //如果确定按钮可用，点击，不可用重新填写验证码
            if (ok1 != null && ok1.exists() && ok1.isEnabled()) {
                ok1.click();
                CODE_TIMER = 0;
                showMsg("----点击确定2---");
                break;
            } else {
                showMsg("----确认按钮不可用，重新请求验证码2---");
                UiObject image = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_addition_code"));
                image.click();
                sleep(ChatClient.overtime_3);
            }
        }
    }

    /**
     * 完成转账后回复服务端
     *
     * @param sumMoney：余额
     * @throws Exception
     */
    public void getUserInfo(String sumMoney) {
        try {
            showMsg("===getUserInfo====");
            String balance = "";
            String type = "";
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_60, "结果页超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject state = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/title_success"));
                if (state.exists()) {
                    showMsg("===转账完成=====");
                    type = state.getText();
                    if (Constants.getStr(type) == 0) {
                        DecimalFormat formater = new DecimalFormat("#0.##");
                        balance = formater.format(Double.parseDouble(sumMoney) - Double.parseDouble(list.get(0).getMoney()));
                        String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                        FileHelper.saveMoneySDFile(false, balance, sumMoneyFile);
                        break;
                    } else {
                        balance = sumMoney;
                        break;
                    }
                }
            }
            ChatClient.reportTransferOrder(BANK_NAME, type, balance, Constants.getStr(type));
            sleep(ChatClient.overtime_1);
            showMsg("===准备检测转账完成=====");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_20, "结果页错误...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject seven = mDevice.findObject(new UiSelector().text("完成").resourceId("com.chinamworld.main:id/ccb_title_right_btn"));
                showMsg("===检测转账完成=====");
                if (seven.exists()) {
                    showMsg("===点击转账完成=====");
                    if (screenHeight != 1920) {
                        showMsg("====点击完成====");
                        seven.click();
                    } else {
                        showMsg("====点击完成坐标====");
                        mDevice.click((int) (647 * ratio), (int) (87 * ratio));
                    }
                    break;
                }
            }
            sleep(ChatClient.overtime_3);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "返回转账页面超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject function = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/tv_function"));
                if (function.exists()) {
                    mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                    showMsg("===转账完成进入转账页面=====");
                    break;
                }
            }
            sleep(ChatClient.overtime_2);
        } catch (Exception e) {
            setDevicesLog(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * 获取余额
     */
    private void getBalance() throws UiObjectNotFoundException {
        sleep(ChatClient.overtime_5);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "余额查找失败...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject zhuanzhang0 = CodeUtils.getUiObject_textOrId("转账金额", "com.chinamworld.main:id/sum_edittext_title");
            UiObject bank0 = CodeUtils.getUiObject_textOrId("选择付款账户", "com.chinamworld.main:id/title_cards_popwindow");
            if (zhuanzhang0.exists()) {
                while (true) {
                    UiObject moeny = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_pay_info"));
                    if (moeny.exists()) {
                        showMsg("====获取金额显示====:" + moeny.getText());
                        if (moeny.getText().indexOf("-") == -1) {
                            String[] res = moeny.getText().split("  ");
                            sumMoney = res[2];
                            sumMoney = sumMoney.replaceAll(",", "");
                            C_updateBalance_W(Double.parseDouble(sumMoney));
                        }
                        break;
                    }
                }
                showMsg("==等待订单=moeny====:" + sumMoney);
                sleep(2000);
                //返回
                back();
                showMsg("=====点击返回====");
                sleep(ChatClient.overtime_2);
                break;
            } else if (bank0.exists()) {
                while (true) {
                    boolean isOutTime1 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "点击银行卡条目", Constants.notReport);
                    if (isOutTime1) {
                        if (screenHeight != 2102) {
                            mDevice.click((int) (50 * ratio), (int) (740 * ratio));
                        } else {
                            mDevice.click(70, 1855);
                        }
                        break;
                    }
                    UiObject selectb0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close_cards_popwindow"));
                    if (selectb0.exists()) {
                        selectb0.click();
                        break;
                    }
                }
                back();
            }
        }
    }

    /**
     * 查账
     *
     * @throws UiObjectNotFoundException
     */
    public void auditOrder() throws UiObjectNotFoundException {
        showMsg("===获取余额=====");
        getBalance();
        //进入转账记录
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "查账页超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/layout_details").className
                    ("android.widget.LinearLayout"));
            if (zhuanzhang.exists()) {
                showMsg("===点击查账按钮===");
                zhuanzhang.click();
                break;
            }
        }
        //进入汇款记录明细
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "进入转账记录超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject next = CodeUtils.getUiObject_textOrId("转账记录", "com.chinamworld.main:id/ccb_title_text");
            if (next.exists()) {
                showMsg("===进入转账记录=====");
                break;
            }
        }
        //获取交易记录
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "没有转账记录...", Constants.notReport);
            if (outTime) {
                ChatClient.reportAuditOrder("6", this);
                break;
            }
            UiObject listView = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/lv_transfer_record"));
            UiObject linearLayout0 = listView.getChild(new UiSelector().className("android.widget.LinearLayout").index(0));
            if (linearLayout0.exists()) {
                String username = CodeUtils.getUiObject_content(linearLayout0.getChild(new UiSelector().resourceId("com.chinamworld" +
                        ".main:id/tv_payee_accname")));
                String money = CodeUtils.getUiObject_content(linearLayout0.getChild(new UiSelector().resourceId("com.chinamworld" +
                        ".main:id/tv_amount")));
                String bankNo = CodeUtils.getUiObject_content(linearLayout0.getChild(new UiSelector().resourceId("com.chinamworld" +
                        ".main:id/tv_payee_accno")));
                showMsg("money:" + sumMoney);
                String bankNo0 = list.get(0).getBankNo().substring(list.get(0).getBankNo().length() - 4, list.get(0).getBankNo().length());
                String bankNo1 = bankNo.substring(bankNo.length() - 4, bankNo.length());
                String moery1 = money.replaceAll(",", "");
                showMsg("==订单金额是否相等==" + String.valueOf(Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1)));
                showMsg("====转账目标名====" + String.valueOf(list.get(0).getUserName().equals(username)));
                showMsg("====转账卡号相等====" + String.valueOf(bankNo0.equals(bankNo1)));
                showMsg("====查到账单====" + username + "---" + moery1 + "---" + bankNo1);
                String state = "1";
                if (Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1) && list.get(0).getUserName()
                        .equals(username) && bankNo0.equals(bankNo1)) {
                    state = "0";
                } else {
                    String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                    String oldMoney = FileHelper.readSDFile(sumMoneyFile);
                    state = Constants.changeInAmount(BANK_FLAG, oldMoney, sumMoney, list.get(0).getMoney());
                }
                ChatClient.reportAuditOrder(state, this);
                showMsg("===转账记录查询完成=====");
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "返回上页超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject back = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ccb_title_left_btn").className("android.widget" +
                    ".Button"));
            if (back.exists()) {
                back.click();
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "转账页刷新超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账").resourceId("com.chinamworld.main:id/ccb_title_text"));
            if (zhuanzhang.exists()) {
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                break;
            }
        }
        showMsg("===转账记录返回转账页面=====");
    }


    public void setTimerun() {
        try {
            CCBMethodName = "setTimerun";
            showMsg("===等待订单=====");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "没有转账按钮", Constants.notReport);
                if (outTime) {
                    break;
                }
                UiObject remittance = CodeUtils.getUiObject_textOrId("转账", "com.chinamworld.main:id/tv_function");
                if (remittance.exists()) {
                    showMsg("=====选择转账按钮========");
                    remittance.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_2);

            while (true) {
                UiObject mLL_pay_card_info = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/ll_pay_info"));
                if (mLL_pay_card_info.exists()) {
                    showMsg("点击银行卡...");
                    mLL_pay_card_info.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_1);

            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "金额上报错误超时", Constants.notReport);
                if (outTime) {
                    return;
                }
                UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("转账金额", "com.chinamworld.main:id/sum_edittext_title");
                UiObject bank = CodeUtils.getUiObject_textOrId("选择付款账户", "com.chinamworld.main:id/title_cards_popwindow");
                if (zhuanzhang.exists()) {
                    long begin_time = System.currentTimeMillis();//开始时间
                    while (true) {
                        long nowtime1 = System.currentTimeMillis();
                        if ((nowtime1 - begin_time) > ChatClient.overtime_15) {
                            showMsg("====获取金额超时====:");
                            break;
                        }
                        UiObject moeny = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_pay_info"));
                        if (moeny.exists()) {
                            showMsg("====获取金额显示====:" + moeny.getText());
                            if (moeny.getText().indexOf("-") == -1) {
                                String[] res = moeny.getText().split("  ");
                                sumMoney = res[2];
                                sumMoney = sumMoney.replaceAll(",", "");
                                C_updateBalance_W(Double.parseDouble(sumMoney));
                                showMsg("===本地保存余额===");
                                String sumMoneyFile = user.getUserName() + BANK_FLAG + "_sumMoney.txt";
                                FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                            }
                            break;
                        }
                    }
                    showMsg("==等待订单=moeny====:" + sumMoney);
                    sleep(ChatClient.overtime_1);
                    break;
                } else if (bank.exists()) {
                    ChatClient.begintime = System.currentTimeMillis();//开始时间
                    while (true) {
                        long nowtime1 = System.currentTimeMillis();
                        if ((nowtime1 - ChatClient.begintime) > ChatClient.overtime_5) {
                            showMsg("坐标选择转账银行卡...");
                            mDevice.click(600, 320);
                            break;
                        }
                        UiObject mIV = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/iv_card_selected"));
                        if (mIV.exists()) {
                            showMsg("选择转账银行卡...");
                            mIV.click();
                            break;
                        }
                    }
                }
            }
            ChatClient.waitExistOrder(ChatClient.overtime_60);
        } catch (Exception e) {
            setDevicesLog(e.toString());
            ChatClient.timer("setTimerun", ChatClient.error);
            e.printStackTrace();
        }
    }

    /**
     * 模拟点击密码
     *
     * @param pad_
     * @throws Exception
     */
    public void setClick(String pad_) {
        char[] abc = "1234567890qwertyuiopasdfghjklzxcvbnm".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    mDevice.click(xy_abc[i][0], (int) (xy_abc[i][1] * ratioH));
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }

    /**
     * 模拟点击自带键盘密码
     *
     * @param pad_
     * @throws Exception
     */
    public void setClickN(String pad_) {
        char[] abc = "123456789.0".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    if (screenHeight != 2102) {
                        mDevice.click((int) (xy_num[i][0] * ratio), (int) (xy_num[i][1] * ratio));
                    } else {
                        mDevice.click((int) (xy_num[i][0] * ratio) + 150, (int) (xy_num[i][1] * ratio) + 150);
                    }
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }


    /**
     * 模拟点击自带键盘密码
     *
     * @param pad_
     * @throws Exception
     */
    public void setClickXunFeiN(String pad_) {
        showMsg("====验证码为====" + pad_);
        char[] abc = "1234567890".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    mDevice.click((xy_num_xunfei[i][0]), (xy_num_xunfei[i][1]));
                    showMsg("====点击数字==" + j);
                    sleep(1000);
                    break;
                }
            }
        }
    }

    /**
     * 返回
     *
     * @throws UiObjectNotFoundException
     */
    public void back() throws UiObjectNotFoundException {
        int sleepTime = ChatClient.overtime_8;
        if (ChatClient.existOrder()) {
            sleepTime = ChatClient.overtime_3;
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > sleepTime) {
                mDevice.pressBack();
                return;
            }
            UiObject selectb0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close_cards_popwindow"));
            if (selectb0.exists()) {
                showMsg("====关闭选择账户弹窗====");
                selectb0.click();
            }
        }
    }

    /**
     * 选择收款银行
     *
     * @throws UiObjectNotFoundException
     */
    public boolean addBank() throws UiObjectNotFoundException {
        showMsg("=====进入选择银行======");
        CCBMethodName = "addBank";
        //进入收款银行选择
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "银行选择页超时...", Constants.isReport);
            if (outTime) {
                return false;
            }
            UiObject bank = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_bank"));
            if (bank.exists()) {
                bank.click();
                sleep(ChatClient.overtime_2);
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("收款银行").resourceId("com.chinamworld.main:id/ctv_title"));
            //判断是否进入转账页面
            if (zhuanzhang.exists()) {
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        String bankName = orderBankName;
        showMsg("=====转入银行========");
        //判断收款银行是否为建设银行
        if (bankName.indexOf("建设") != -1) {
            while (true) {
                UiObject bankName_search = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/search_et"));
                if (bankName_search.exists()) {
                    sleep(ChatClient.overtime_1);
                    //点击热门的建设银行图标
                    mDevice.click((int) (92 * ratio), (int) (337 * ratio));
                    showMsg("=====坐标点击同行========" + bankName);
                    break;
                }
            }
        } else {
            //获取收款银行控件
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "搜索栏超时...", Constants.isReport);
                if (outTime) {
                    return false;
                }
                UiObject bankName_search = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/search_et"));
                if (bankName_search.exists()) {
                    sleep(ChatClient.overtime_1);
                    //检索收款银行
                    bankName_search.setText(orderBankName);
                    showMsg("=====检索银行========" + bankName);
                    break;
                }
            }


            //检查是否检索到银行
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "银行名查找超时...", Constants.notReport);
                if (outTime) {
                    ChatClient.reportTransferOrder(BANK_NAME, "收款银行名异常", sumMoney, 1);
                    UiObject cib_close = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/cib_close"));
                    if (cib_close.exists()) {
                        cib_close.click();
                    }
                    return false;
                }
                UiObject bankname = CodeUtils.getUiObject_textOrClass(orderBankName, "android.widget.TextView");
                if (bankname.exists()) {
                    showMsg("=====检索到银行：========" + bankName);
                    bankname.click();
                    break;
                }
            }
        }
        return true;
    }

    //建行实时监测网络异常处理
    public void CloseNetwork() {
        final String str = "由于您曾在另一台设备上绑定，为保证您的资金安全，资金转出类交易的单笔限额为5000元，日累计限额为5000" +
                "元。若您需提高转账限额，可登录原绑定设备确认设备变更，网银盾客户可登录网银确认变更，您也可通过我行营业网点办理。";
        final String str1 = "验证码有误";
        final String str2 = "查询帐户开户机构失败";
        new Thread() {
            public void run() {
                try {
                    while (true) {
                        sleep(ChatClient.overtime_1);
                        UiObject network1 = CodeUtils.getUiObject_textOrId("关闭", "com.chinamworld.main:id/dlg_right_tv");
                        UiObject network2 = CodeUtils.getUiObject_textOrId("确定", "com.chinamworld.main:id/dlg_right_tv");
                        UiObject okDialog = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_dlg_content"));
                        if (okDialog != null && okDialog.exists()) {
                            showMsg("拦截捕获异常弹窗内容:" + okDialog.getText());
                            if (okDialog.getText().contains(str1)) {
                                return;
                            }
                            if (!okDialog.getText().equals(str) && !okDialog.getText().contains(str2)) {
                                if (network2.exists()) {
                                    showMsg("=======network=====" + CCBMethodName);
                                    network2.click();
                                    setContinue(CCBMethodName);
                                }
                            }
                        }

                        if (okDialog != null && network1.exists()) {
                            showMsg("=======network=====" + CCBMethodName);
                            showMsg("--------拦截捕获异常关闭按钮--------");
                            network1.click();
                            setContinue(CCBMethodName);
                        }
                    }
                } catch (UiObjectNotFoundException e) {
                    showMsg("建行实时监测网络异常处理===未找到控件异常====" + e.toString());
                } catch (Exception e) {
                    showMsg("建行实时监测网络异常处理===异常====" + e.toString());
                    setDevicesLog(e.toString());
                    e.printStackTrace();
                }
            }
        }.start();
    }

    /**
     * 遇到网络异常时继续执行
     */
    public void setContinue(String name) throws UiObjectNotFoundException {
        addWorkTime(ChatClient.overtime_30);
        if ("Login".equals(name)) {//点击登录
            showMsg("===登录网络异常====");
            while (true) {
                UiObject username = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_userInfo"));
                if (username.exists()) {
                    String Uname = username.getText();
                    if (!Uname.equals("身份信息获取中...")) {
                        if (Uname.equals("获取用户信息失败")) {
                            while (true) {
                                UiObject btn_getUserInfo = mDevice.findObject(new UiSelector().resourceId("com.chinamworld" +
                                        ".main:id/btn_getUserInfo"));
                                if (btn_getUserInfo.exists()) {
                                    btn_getUserInfo.click();
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    }
                }
            }
            //登录
            UiObject lgbut = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_confirm"));
            lgbut.click();
            CCBMethodName = "Login";
        } else if ("setTimerun".equals(name)) {//进入转账
            showMsg("===等待订单网络异常====");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "选择付款账户超时...", Constants.notReport);
                if (outTime) {
                    mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                    break;
                }
                UiObject bank = CodeUtils.getUiObject_textOrId("选择付款账户", "com.chinamworld.main:id/title_cards_popwindow");
                if (bank.exists()) {
                    ChatClient.begintime = System.currentTimeMillis();//开始时间
                    while (true) {
                        boolean outTime1 = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "底部弹窗超时...", Constants.notReport);
                        if (outTime1) {
                            back();
                            break;
                        }
                        UiObject selectb0 = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/close_cards_popwindow"));
                        if (selectb0.exists()) {
                            selectb0.click();
                            break;
                        }
                    }
                    break;
                }
            }
            CCBMethodName = "setTimerun";
        } else if ("remittanceLongin".equals(name)) {//进入转账
            showMsg("===转账网络异常====");
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "搜索栏超时...", Constants.notReport);
                if (outTime) {
                    mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                }
                UiObject bankl = mDevice.findObject(new UiSelector().text("选择付款账户").resourceId("com.chinamworld.main:id/title_cards_popwindow"));
                UiObject username_ = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/et_cash_name"));
                if (username_.exists() || bankl.exists()) {
                    break;
                }
            }
        } else if ("addBank".equals(name)) {//选择银行
            showMsg("===选择银行网络异常====");
            sleep(ChatClient.overtime_2);
            while (true) {
                UiObject bank = CodeUtils.getUiObject_textOrId("请选择收款银行", "com.chinamworld.main:id/tv_bank");
                if (bank.exists()) {
                    bank.click();
                    CCBMethodName = "addBank";
                    break;
                }
            }
        } else if ("Submit".equals(name)) {//提交转账
            showMsg("===点击下一步网络异常====");
            while (true) {
                UiObject ok = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/btn_right1"));
                if (ok.exists()) {
                    ok.click();
                    CCBMethodName = "Submit";
                    sleep(ChatClient.overtime_2);
                    break;
                }
            }
        } else if ("Re_send".equals(name)) {
            showMsg("===短信获取网络异常====");
        }
    }

    /**
     * 获取短信序列号
     *
     * @throws UiObjectNotFoundException
     */
    public void getCodeType() throws UiObjectNotFoundException {
        showMsg("===获取验证码序列号====");
        while (true) {
            UiObject text = mDevice.findObject(new UiSelector().resourceId("com.chinamworld.main:id/tv_tips"));
            if (text.exists() && !TextUtils.isEmpty(text.getText())) {
                Constants.TV_TIPS = text.getText();
                showMsg("===验证码序列号====" + Constants.TV_TIPS);
                break;
            }
        }
    }

    /**
     * 发送限额信息
     */
    private void sendRePropcessInfo(String info) throws UiObjectNotFoundException {
        ChatClient.reportTransferOrder(BANK_NAME, info, sumMoney, 1);
        showMsg("===删除订单完成====");
        sleep(ChatClient.overtime_8);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "返回超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject leftBack = mDevice.findObject(new UiSelector().className("android.widget.Button").resourceId("com.chinamworld" +
                    ".main:id/ccb_title_left_btn"));
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("转账", "com.chinamworld.main:id/ccb_title_text");
            showMsg("===检测转账页面的返回键====");
            if (zhuanzhang.exists() || leftBack.exists()) {
                showMsg("===点击转账页面的返回键====");
                leftBack.click();
                break;
            }
        }
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "预约转账超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            UiObject zhuanzhang = CodeUtils.getUiObject_textOrId("预约转账", "com.chinamworld.main:id/tv_function");
            if (zhuanzhang.exists()) {
                showMsg("===转账完成进入转账页面=====");
                mDevice.click((int) (87 * ratio), (int) (247 * ratio));
                break;
            }
        }
    }


    /**
     * 发送未搜索到开户行信息
     */
    private void sendUnBankInfo(String info) {
        ChatClient.reportTransferOrder(BANK_NAME, info, sumMoney, 1);
        showMsg("===删除订单完成====");
    }

    public void showMsg(String msg) {
        LogToFile.showLog("建设银行", msg);
    }
}